﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
</head>
<body>
    <h3>Id Token</h3>
    <div id="id_token"></div>
    <h3>Access Token</h3>
    <div id="access_token"></div>
    <script src="lib/oidc-client/oidc-client.js"></script>
    <script type="text/javascript">
        window.onload = callback;

        function callback() {
            const config = {
                authority: 'https://localhost:8080',
                client_id: 'js',
                redirect_uri: `${window.location.origin}/callback.html`,
                response_type: 'code',
                scope: 'openid profile api',
                loadUserInfo: false
            };
            const mgr = new Oidc.UserManager(config);

            mgr.signinRedirectCallback().then(() => {
                mgr.getUser().then((user) => {
                    if (user) {
                        document.onload = function () {
                            document.getElementById('id_token').setAttribute('value', user.id_token);
                            document.getElementById('access_token').setAttribute('value', user.access_token);
                        }
                        console.log(user)
                    } else {
                        console.log('unauthorize')
                    }
                })
            });
        }
    </script>
</body>
</html>